﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ecopsy.DataTier;
using SqlLibrary;
using Ecopsy.Tools;
using Ecopsy.DataTier.SqlLibrary;

namespace AgencyEntityLib.BaseEntity
{
    public class TaskList : SqlStatmentPropertyOf_PagingList
    {
        public class sqlLoadStatment : ListLoadStatment
        {
            public override string vPropertyOf_ViewName
            {
                get
                {
                    return " dbo.Get_v_srch_PropertyOfTask('" + DateTimeTools.GetSqlDate(dtStart) + "','" + DateTimeTools.GetSqlDate(_dtFinish) + "') ";
                }
            }

            public override string Source_ViewName
            {
                get
                {   
                    return " dbo.GetTaskList("+(ClientID.Length==0?"default":"'"+ClientID+"'")+","
                    +(EmplID .Length ==0?"default":"'"+EmplID+"'")+",'" 
                    +DateTimeTools.GetSqlDate (dtStart) + "','" + DateTimeTools.GetSqlDate(_dtFinish) + "') ";
                }
            }

            private string GetSqlDateString(DateTime dt)
            {
                return dt.ToString("G");
                
            }

            private DateTime _dtStart = Context.AgencyLib_GlobalConstants.MinDate;
            private DateTime _dtFinish = Context.AgencyLib_GlobalConstants.MaxDate;

            public DateTime dtStart { get { return _dtStart; } set { _dtStart = value; } }
            public DateTime dtFinish { get { return _dtFinish; } set { _dtFinish = value; } }

            private string _ClientID = string.Empty;
            public string ClientID
            {
                get { return _ClientID; }
                set { _ClientID = value; }
            }

            private string _EmplID = string.Empty;
            public string EmplID
            {
                get { return _EmplID; }
                set { _EmplID = value; }
            }

            //protected override string GetPropertyOfSql()
            //{

            //    string where = BuildStatment ();
            //    string TypeFiltr= (CtegoriaID .Length ==0?"":" PARAM='B5F499C5-B48B-4B0B-AB2B-73320C746B53' AND VALUE='"+CtegoriaID +"'");

                
            //    if (where.Length == 0) return " select Id into #SelectList  from  " + Source_ViewName + (TypeFiltr.Length == 0 ? " " :
            //        " where  id in (select id from v_srch_PropertyOfTask where" + TypeFiltr + ") ");

            //    string sql = " select Id into #SelectList  from" +
            //      "(" +
            //      "select " +
            //          "ViewName.ID as ID," +
            //          "1 as ItemCount " +
            //      "from " +
            //          vPropertyOf_ViewName + " as ViewName " +
            //      " where 	" +
            //       where + (CtegoriaID.Length ==0?"":" OR " ) + TypeFiltr+
            //          ") as res   " +
            //          "group by res.ID,ItemCount " +
            //          "having sum(ItemCount)= " + ((CtegoriaID.Length==0?0:1)+ this.ChildNodes.Count).ToString();

            //    return sql;
            //}

            //protected override string GetResultSetSql()
            //{
            //    return " declare @r_count int select v_task.ID,[XML] into 	#ResultSet from v_task  join #SelectList on v_task.ID=#SelectList.Id DECLARE @OutputRwCnt  INT select @OutputRwCnt=count(*) from #ResultSet ";
            //}
           

            private string _CtegoriaID = string.Empty;
            public string CtegoriaID
            {
                get { return _CtegoriaID; }
                set { _CtegoriaID = value; }
            }
            
        }
      
    

    }
}
